package com.jr.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;

/**
 * @Function：使用druid连接池连接数据库
 * @Author 梁明哲
 * @Email 424577090@qq.com
 * @Package com.jr.service.impl
 * @Project InvoiceManage
 * @Date 2023-02-20 09:11:08
 */
public class PoolUtil {
    private static DataSource dataSource;

    static {
        Properties properties = new Properties();
        try {
            properties.load(PoolUtil.class.getClassLoader().getResourceAsStream("druid.properties"));
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static DataSource getDataSource() {
        return dataSource;
    }
}
